package handle

import (
	"context"
	"fmt"
	"goodSrv/model/mentod"
	"goodSrv/proto/GoodSrv"
	"strconv"
)

type Good struct {
}

func (g *Good) GoodList(ctx context.Context, req *GoodSrv.GoodListReq) (*GoodSrv.GoodListRes, error) {
	var stu []*GoodSrv.GoodList
	list, err := mentod.GoodList()
	if err != nil {
		return nil, fmt.Errorf("列表展示失败")
	}
	for _, v := range list {
		stu = append(stu, &GoodSrv.GoodList{
			GoodName:  v.GoodName,
			GoodPrice: float32(v.GoodPrice),
			GoodTitle: v.GoodTitle,
			GoodNum:   strconv.Itoa(v.GoodNum),
			GoodType:  int64(v.GoodType),
		})
	}

	return &GoodSrv.GoodListRes{List: stu}, nil
}
